<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/lib/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/layui/css/layui.css"></link>
<link type="text/css" rel="stylesheet" href="__PUBLIC__/Admin/css/H-ui.css"/>
<link type="text/css" rel="stylesheet" href="__PUBLIC__/Admin/css/H-ui.admin.css"/>
<link type="text/css" rel="stylesheet" href="__PUBLIC__/Admin/font/font-awesome.min.css"/>

<script type="text/javascript" src="__PUBLIC__/Admin/js1/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/layer/layer.js"></script>

<title>编辑用户</title>
</head>
<body>
<div class="pd-20">
  <div class="Huiform">
      <table class="table table-bg">
        <tbody>
          <tr>
            <th width="100" class="text-r"><span class="c-red">*</span> 用户名：</th>
            <td><input type="text" style="width:300px" class="input-text" value="{$name}" placeholder="" id="user-name" name="user-name" datatype="*2-16" nullmsg="用户名不能为空"></td>
          </tr> 
           <tr>
            <th class="text-r">邮箱：</th>
            <td><input type="email" style="width:300px" class="input-text" value="{$email}" placeholder="" id="user-email" name="user-email"></td>
          </tr> 
          <tr>
              <th class="text-r">所属角色：</th>
             
                 <if condition="$arr">
                    <foreach name="arr" item="v">
                   <table>
                    <td>
                     <if condition="$v.id eq $role_id">
                       <input type="checkbox" name="role_ids" value="{$v.id}" style="margin-left:120px" checked="checked"/>
                     <else/>
                        <input type="checkbox" name="role_ids" value="{$v.id}" style="margin-left:120px"/>
                     </if>
                         {$v.name}
                    </td>
                    </table>
                    </foreach>
                 </if>
              
          </tr>
        </tbody>
      </table>
         &nbsp;&nbsp;&nbsp;&nbsp;
      <div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input type="hidden" value="{$id}" name="id"/>
				<button type="submit" class="btn btn-success radius" id="commit" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
  </div>
</div>
<script>
/*
*checkbox
*bind() 当点击事件  显示或隐藏
*is()  遍历  根据选择器、元素或 jQuery 对象来检测匹配元素集合，
*          如果这些元素中至少有一个元素匹配给定的参数，则返回 true
*not() 删除集合中匹配的元素
*
*/
$(":checkbox").bind("click",function(){
	 if(!$(this).is(":checked")) {
		 return false;
	 }
     $(":checkbox").not(this).attr("checked",false);
  })
 /*
 *each() 遍历
 *
 *prop() 添加cheecked属性 
 *push() 
 *
 */
$('#commit').click(function(){
	var name=$('#user-name').val();	  	  
	var email=$('#user-email').val();
	var id = $("input:hidden[name='id']").val();
	var role_ids=[];
	$(':checkbox').each(function() {
		if($(this).prop('checked')) {
          role_ids.push($(this).val());  
		}
	}) 
	
    $.post('__APP__/Admin/User/user_alter',{name:name,email:email,id:id,role_ids:role_ids},function(obj){
    	if(obj.pass==1) {
    	   layer.msg(obj.msg,{time:1000,inco:1},function(){
    		   location.reload();
    	   });
    	}
    	if(obj.pass==2) {
    		var index=layer.msg(obj.msg,{time:1000,inco:2},function(){
    			parent.layer.close(index);
				window.parent.location.reload();

    		});
    	}

    })
})
</script>
</body>
</html>